home *** CD-ROM | disk | FTP | other *** search
- unit FontDlgU;
-
- interface
-
- uses
- Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
- StdCtrls, ComCtrls, Buttons;
-
- type
- TForm1 = class(TForm)
- FDlg: TFontDialog;
- Edit1: TEdit;
- SpeedButton1: TSpeedButton;
- RichEdit1: TRichEdit;
- procedure SpeedButton1Click(Sender: TObject);
- procedure FDlgApply(Sender: TObject; Wnd: HWND);
- private
- { Private declarations }
- public
- { Public declarations }
- end;
-
- var
- Form1: TForm1;
-
- implementation
-
- {$R *.DFM}
-
- procedure TForm1.SpeedButton1Click(Sender: TObject);
- begin
- if ActiveControl is TEdit then
- FDlg.Font := TEdit(ActiveControl).Font
- else
- if ActiveControl is TRichEdit then
- TRichEdit(Activecontrol).SelAttributes.Assign(FDlg.Font);
- //Launch dialog. If it returns True, and
- //we have an OnApply handler, call it
- if FDlg.Execute and Assigned(FDlg.OnApply) then
- FDlg.OnApply(FDlg, 0)
- end;
-
- procedure TForm1.FDlgApply(Sender: TObject; Wnd: HWND);
- begin
- //Could check here that there is in fact a need to apply
- //the font, by comparing, but for brevity, I'll skip it
- if ActiveControl is TEdit then
- TEdit(ActiveControl).Font := TFontDialog(Sender).Font
- else
- if ActiveControl is TRichEdit then
- TRichEdit(ActiveControl).SelAttributes.Assign(TFontDialog(Sender).Font)
- end;
-
- end.
-